package edu.tyut.game.logic

import edu.tyut.game.logic.Repository.fire
import edu.tyut.game.logic.network.GameNetWork
import edu.tyut.game.utils.LogUtils

object FlyingFlowerOrderRepository {

    private val tag = this::class.java.name

    fun getWinRateRankTotalRoundsRank() = fire {
        val res = GameNetWork.getWinRateRankTotalRoundsRank()
        if (res.status == "ok"){
            Result.success(res.data)
        }else{
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }

    fun getWinRateRank() = fire {
        val res = GameNetWork.getWinRateRank()
        if (res.status == "ok"){
            Result.success(res.data)
        }else{
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }

    fun getTotalRoundsRank() = fire {
        val res = GameNetWork.getTotalRoundsRank()
        if (res.status == "ok"){
            Result.success(res.data)
        }else{
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }

    fun getContentsByWord(word: String) = fire {
        LogUtils.d(tag, word)
        val res = GameNetWork.getContentsByWord(word)
        if (res.status == "ok") {
            Result.success(res.data)
        } else {
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }

    fun gameOver(uid: Int) = fire {
        LogUtils.d(tag, uid.toString())
        val res = GameNetWork.gameOver(uid)
        if (res.status == "ok") {
            Result.success(res.data)
        } else {
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }

    fun isExistPoem(content: String) = fire {
        LogUtils.d(tag, content)
        val res = GameNetWork.isExistPoem(content)
        if (res.status == "ok") {
            Result.success(res.data)
        } else {
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }

    fun win(uid: Int) = fire {
        LogUtils.d(tag, "赢游戏埋点")
        val res = GameNetWork.win(uid)
        if (res.status == "ok") {
            Result.success(res.data)
        } else {
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }

    fun lose(uid: Int) = fire {
        LogUtils.d(tag, "输游戏埋点")
        val res = GameNetWork.lose(uid)
        if (res.status == "ok") {
            Result.success(res.data)
        } else {
            LogUtils.d(tag, res.msg)
            Result.failure(Exception(res.msg))
        }
    }
}